#ifndef OWL_EYE_HAAR_H
#define OWL_EYE_HAAR_H

namespace oe {

typedef double decimal;

struct Coefficient {
  int idx;
  decimal val;
  bool operator<(const Coefficient &right) const {
    return val > right.val;
  }
};

class Haar {
public:
  Haar(int dim, int m);
  ~Haar();

  void Transform(decimal *A[3]) {
    Transform(A[0], A[1], A[2]);
  }

  void Transform(decimal *A, decimal *B, decimal *C) {
    RGB2YIQ(A, B, C);
    
    Transform(A);
    Transform(B);
    Transform(C);

    A[0] /= 256 * 128;
    B[0] /= 256 * 128;
    C[0] /= 256 * 128;
  }
  
  void Transform(decimal *A);
  void GetCoefs(decimal *A[3], int *sigs[3], double avg[3]) {
    for (int i = 0; i < 3; ++i) {
      GetCoefs(A[i], sigs[i], &avg[i]);
    }
  }
  void GetCoefs(const decimal *a, const decimal *b, const decimal *c,
                int *sig0, int *sig1, int *sig2, double avg[3]) {
    GetCoefs(a, sig0, &avg[0]);
    GetCoefs(b, sig1, &avg[1]);
    GetCoefs(c, sig2, &avg[2]);
  }
  void GetCoefs(const decimal *A, int *sig, double *avg);
private:
  void Haar1D(decimal *A);
  void Haar1Pass(decimal *A);
  void Transpose(decimal *A);
  void RGB2YIQ(decimal *R, decimal *G, decimal *B);
private:
  decimal *array_;
  int dim_;
  int m_;
  int size_;
  //decimal 
  static const decimal kInvSqrt2;
};
} // oe

#endif // OWL_EYE_HAAR_H
